home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / fd / read.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  672b  |  39 lines

  1.  
  2. /*
  3.  *  READ.C
  4.  *
  5.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  6.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  7.  *    DICE-LICENSE.TXT.
  8.  */
  9.  
  10. #include <clib/dos_protos.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <fcntl.h>
  14. #include <ioctl.h>
  15. #include <errno.h>
  16.  
  17. int
  18. read(fd, buf, bytes)
  19. int fd;
  20. void *buf;
  21. unsigned int bytes;
  22. {
  23.     _IOFDS *d;
  24.     int n = -1;
  25.  
  26.     chkabort();
  27.     if (d = __getfh(fd)) {
  28.     if (!(d->fd_Flags & O_WRONLY)) {
  29.         if (d->fd_Exec)
  30.         return((*d->fd_Exec)(d->fd_Fh, IOC_READ, buf, (void *)bytes));
  31.         n = Read(d->fd_Fh, buf, bytes);
  32.     } else {
  33.         errno = ENOPERM;
  34.     }
  35.     }
  36.     return(n);
  37. }
  38.  
  39.